(function () {
    $.fn.extend({
        order() {

            var data = [{ id: 1, name: "哈根达斯", price: 18, image: "./images/1.jpg" },
            { id: 2, name: "香奈儿冰淇淋", price: 28, image: "./images/2.jpg" },
            { id: 3, name: "深海鳕鱼", price: 20, image: "./images/3.jpg" },
            { id: 4, name: "牛肉", price: 16, image: "./images/4.jpg" },
            { id: 5, name: "可口冰淇淋", price: 12, image: "./images/5.jpg" },
            { id: 6, name: "南海虾", price: 38, image: "./images/6.jpg" }]
            var strHtml = ``;

            function str(data) {
                $.each(data, function (item, key) {
                    //     strHtml += `<div class=item><img src=${key.image} alt=""><p>名称:${key.name}</p><p>价格:${key.price}</p><p><a class=add data-meun-id=${key.id} href="javascript:void(0)">加入购物车</a></p></div>`
                    strHtml += ` <li class=${item}>

                                <div class="tiemBox">
                                
                                <div class="pic"><img src=${key.image} alt=""><a href="#"></a></div>
                                <div class="info-box">
                                    <p class="desc">${key.name}</p><s></s>
                                    <div class="info-detall">
                                        <div class="log"><img src="./images/brandlog7.png" alt=""></div>
                                        <div class="price-box">
                                            <p class="oprice">专柜价<span>￥</span><span>${key.price}</span></p>
                                            <p class="price">狂欢价<span>￥</span><span class="item-rpiec-num">252</span></p>
                                        </div>
                                    </div>
                                </div>
                           
                                <div class=btn data-meun-id=${key.id}>
                                    立即购买
                                </div>
                            </div>
                        </li>`
                    return strHtml;
                });
            }
            // str(data);
            $('.act-list').append(strHtml)
            $('.act-list').on('click', function (event) {
                event.stopPropagation();
                var target = event.target
                console.log(target.nodeName);
                // console.log(target.className);
                
                // if (!(target.nodeName == 'DIV' && target.className == 'btn')) {
                //     return false;
                // }
                var Id = $(target).attr('data-meun-id');
                var current = data.filter(function (item) {
                    return item.id == Id;
                })[0];
                // console.log(current);
                var localData = JSON.parse(localStorage.getItem('meun') || '[]');
                // console.log(current.id);
                var isAdd = localData.some(function (item) {
                    if (item.id == current.id) {
                        item.num = Number(item.num) + 1;
                        return true;
                    }
                })
                if (isAdd == false) {
                    current.num = 1;
                    localData.push(current);
                }
                localStorage.setItem('meun', JSON.stringify(localData));
                alert('加入成功!')
            })
        }

    })
})()
$(function () {
    $('mallpage').order()
})